Avoid overwriting the lockfile if there are no changes
authorGleb Kozyrev <gleb@gkoz.com>
Fri, 30 Oct 2015 11:18:19 +0000 (13:18 +0200)
committerGleb Kozyrev <gleb@gkoz.com>
Fri, 30 Oct 2015 18:51:26 +0000 (20:51 +0200)
src/cargo/ops/lockfile.rs

index da8aac7a108555e48516787bb5dde63bddb57457..3a0ef553f982205127829c7f695e990120485281 100644 (file)
@@ -68,6 +68,15 @@ pub fn write_lockfile(dst: &Path, resolve: &Resolve) -> CargoResult<()> {
         None => {}
     }
 
+    // Load the original lockfile if it exists.
+    if let Ok(orig) = paths::read(dst) {
+        if out == orig {
+            // The lockfile contents haven't changed so don't rewrite it.
+            // This is helpful on read-only filesystems.
+            return Ok(())
+        }
+    }
+
     try!(paths::write(dst, out.as_bytes()));
     Ok(())
 }